$(function () {
    //======================
    //======设置查询条件========
    //======================
    //内部公司
    $("#cwkc_toolbar [name='gsId']").ljgsjgtree(1,123);
    //起始时间
    $("#cwkc_toolbar [name='endDate']").datebox();
    //搜索按钮
    $("#cwkc_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams: {
                date: $("#cwkc_toolbar [name='endDate']").val(),
                gsId: $("#cwkc_toolbar [name='gsId']").val(),
                wzbm: $("#cwkc_toolbar [name='wzbm']").val(),
                wzdl: $("#cwkc_toolbar [name='wzdl']").val()
            }});
    });

    $("#cwkc_toolbar a[name='dc']").click(function(){
        window.open($.webPath() + "/report/cwkc/export?date=" + $("#cwkc_toolbar [name='endDate']").val() +
        "&gsId=" + $("#cwkc_toolbar [name='gsId']").val() || '' +
        "&wzbm=" + $("#cwkc_toolbar [name='wzbm']").val() +
        "&wzdl=" + $("#cwkc_toolbar [name='wzdl']").val() || '');
    });


//======================
//========统计列表========
//======================
    var columns = [
        [
            {field: 'gsjc', title: '公司名称', width: 145,align: 'center'},
            {field: 'code', title: '物资编号', width: 145,align: 'center'},
            {field: 'ggmc', title: '品名', width: 145,align: 'center'},
            {field: 'ggxh', title: '规格', width: 145,align: 'center'},
            {field: 'th', title: '图号', width: 35,align: 'center'},
            {field: 'dw', title: '单位', width: 29,align: 'center'},
            {field: 'kcsl', title: '库存数量',align: 'right', formatter:function(value){
                var val = formatSl(value,",");
                return val;
            },width: 145},
            {field: 'kcje', title: '库存金额',align: 'right',formatter:function(value){
                var val = formatJe2(value,",");
                return val;
            }, width: 145},
            {field: 'wjscksl', title: '未开票数量',align: 'right', formatter:function(value){
                var val = formatSl(value,",");
                return val;
            },width: 145},
            {field: 'wjsckje', title: '未开票金额',align: 'right', formatter:function(value){
                var val = formatJe2(value,",");
                return val;
            },width: 145}
        ]
    ];

    var grid = $('#cwkc_grid').datagrid({
        url: $.webPath() + '/report/cwkc/cwkcList',
        toolbar: "#cwkc_toolbar",
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        fit: true,
        fitColumns: true,
        pageNumber: 1,
        showFooter: true,
        queryParams: {
            date: $("#cwkc_toolbar [name='endDate']").val()
        },
        columns: columns
    });
});
